﻿//==============================================================================
// File: ITask.cs
// Created: 2010-06-07
// Author: Piotr Włodek, Arkadiusz Świerczek
//==============================================================================
// This file is a part of MAMMOTH project.
// Copyright (C) 2010 AGH University of Science and Technology, Krakow.
// https://caribou.iisg.agh.edu.pl/trac/mammoth
//
// Mammoth is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// Mammoth is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with Mammoth. If not, see http://www.gnu.org/licenses/.
//==============================================================================

using System;

namespace WpfRcp.Core.Threading
{
    /// <summary>
    /// Represents an executable task.
    /// </summary>
    public interface ITask
    {
        /// <summary>
        /// Runs the task.
        /// </summary>
        /// <returns>Returns any value which the outcome of the task.</returns>
        object Run();
    }

    /// <summary>
    /// Represents an event arguments for the task completed event.
    /// </summary>
    public class TaskCompletedEventArgs : EventArgs
    {
        private readonly ITask m_Task;
        private readonly object m_Result;

        public TaskCompletedEventArgs(ITask task, object val)
        {
            if (task == null) throw new ArgumentNullException("task");

            m_Task = task;
            m_Result = val;
        }

        public ITask Task
        {
            get { return m_Task; }
        }

        public object Result
        {
            get { return m_Result; }
        }
    }

    public class TaskErrorEventArgs : EventArgs
    {
        private readonly Exception m_Exception;
        private readonly ITask m_Task;

        public TaskErrorEventArgs(ITask task, Exception exception)
        {
            if (task == null) throw new ArgumentNullException("task");
            if (exception == null) throw new ArgumentNullException("exception");

            m_Task = task;
            m_Exception = exception;
        }

        public Exception Exception
        {
            get { return m_Exception; }
        }

        public ITask Task
        {
            get { return m_Task; }
        }
    }
}